package com.lyf.juc.practice.lock;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author LYF
 * @date 2022/7/3
 */
public class InterruptTests {
    private static volatile boolean isStop = false;
    private static AtomicBoolean atomicBoolean = new AtomicBoolean(false);
    static Thread t=null;
    static void start1(){
        t = new Thread(()->{
            while (true){
                if(isStop){
                    System.out.println("停止运行...");
                    break;
                }
//                if(Thread.currentThread().isInterrupted()){
//                    System.out.println("停止运行...");
//                    break;
//                }
                System.out.println("运行...");
            }

        });//.start();
        t.start();
    }
    static void start2(){
        new Thread(()->{
            isStop = true;
            //atomicBoolean.set(true);
        }).start();
    }


    static void start3(){
        new Thread(()->{
            t.interrupt();
        }).start();
    }


    public static void main(String[] args) throws InterruptedException {
        start1();
        TimeUnit.MILLISECONDS.sleep(1);
        start2();
    }

}
